﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Steer
{
    public partial class Circle : UserControl
    {
        private double _radius;
        private Color _color;

        public double Radius {
            get { return _radius; }
            set { _radius = value; }
        }

        public Vector2D position {
            get { return new Vector2D(_compositeTransform.TranslateX, _compositeTransform.TranslateY); }
        }

        private CompositeTransform _compositeTransform;
        private TransformGroup _transformGroup;

        public Circle()
        {
            InitializeComponent();
            Loaded += new RoutedEventHandler(Circle_Loaded);
        }

        public void init(double radius,Color color) {
            xCircle.Width = radius * 2;
            xCircle.Height = radius * 2;
            xCircle.Fill = new SolidColorBrush(color);
            xCircle.Margin = new Thickness(-radius, -radius, 0, 0);
            _radius = radius;
            _color = color;
        }

        void Circle_Loaded(object sender, RoutedEventArgs e)
        {
            var transformGroup = this.RenderTransform as TransformGroup;
            if (transformGroup == null)
            {
                _transformGroup = new TransformGroup();
                this.RenderTransform = _transformGroup;
                _compositeTransform = new CompositeTransform();
                _transformGroup.Children.Add(_compositeTransform);
            }
        }

        public double x
        {
            get
            {
                return _compositeTransform.TranslateX;
            }
            set
            {
                _compositeTransform.TranslateX = value;
            }
        }

        public double y
        {
            get
            {
                return _compositeTransform.TranslateY;
            }
            set
            {
                _compositeTransform.TranslateY = value;
            }
        }
    }
}
